public class MyBlockingQueue {

    private int[] nums = new int[100];
    private volatile int head = 0;
    private volatile int tail = 0;
    private volatile int size = 0;

    //入队列
    synchronized public void put(int value) throws InterruptedException{
        if(size == nums.length){
            this.wait();
        }
        nums[tail] = value;
        tail++;
        if(tail == nums.length){
            tail = 0;
        }
        size++;
        this.notify();
    }

    //出队列
    synchronized int take() throws InterruptedException{
        if(size == 0){
            this.wait();
        }
        int value = nums[head];
        head++;
        if(head == nums.length){
            head = 0;
        }
        size--;
        this.notify();
        return value;
    }
}
